package com.facotry.service.Impl;

import com.facotry.entity.depManage;
import com.facotry.entity.depManageVo;
import com.facotry.mapper.setMapper;
import com.facotry.service.setService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author 崔瑜航
 * @date 2024/7/23
 * @desc
 */
@Service
public class setServiceImpl implements setService {

    @Autowired
    private setMapper setMapper;

    @Override
    public List<depManageVo> findAllDep() {

        return setMapper.findAllDep();
    }

    @Override
    public boolean addDep(depManage depManage) {
        depManage.setDepCreateTime(new Date());
        //查询祖先id
       String ancestorId = setMapper.sserch(depManage.getParentDepId());
       //拼接
        String ancestors = ancestorId+","+depManage.getParentDepId();
        depManage.setAncestors(ancestors);
        return setMapper.addDep(depManage);
    }

    @Override
    public boolean editDep(depManage depManage) {
        return setMapper.editDep(depManage);
    }

    @Override
    public boolean hasChildren(int id) {
        List<depManage> list = setMapper.hasChildren(id);
        if (list.size()>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean depId(int id) {
        return setMapper.depId(id);
    }
}
